#pragma once

#include <string>
#include <fstream>
#include <vector>

using namespace std;

class ExternalSorter {
public:
	ExternalSorter(const string& _inputFile) : inputFile(_inputFile) {}
	void Sort(const string& inputFile);

private:
	typedef pair<int, int> ValueIndex;
	const string& inputFile;

	bool getChunk(ifstream& input, vector<int>& chunkBuffer) const;
	void writeChunk(const string& chunkFileName, vector<int>& chunkBuffer) const;
	void sortedMerge(const vector<string>& tempFiles, const string& outputFile);
};

